//
//  LoginController.m
//  gungunchou
//
//  Created by lyzbmacos3 on 2019/2/20.
//  Copyright © 2019年 xskj. All rights reserved.
//

#import "LoginController.h"

@interface LoginController ()
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UITextField *usrText;
@property (weak, nonatomic) IBOutlet UITextField *pasText;

@end

@implementation LoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.loginBtn.layer.cornerRadius = 12;
    self.loginBtn.layer.masksToBounds = YES;
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"USR_IS_L"];
    
}

- (IBAction)loginClick:(id)sender {
    NSDictionary *parmDic = [NSDictionary dictionaryWithObjectsAndKeys:self.usrText.text,@"Mobile",self.pasText.text,@"Pwd", nil];
    [[CGNetManage shared] httpLoginWithParams:parmDic Completed:^(NSDictionary *result) {
        NSNumber *state = [result objectForKey:@"State"];
        NSString *msg = [result objectForKey:@"Msg"];
        if (msg.length>0) {
            [LICGToast showWithText:msg];
        }
        if (state.integerValue == 1) {
            //success
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"USR_IS_L"];
            
            if (self.tabBarController) {
                self.tabBarController.selectedIndex = 0;
            }
            else if (KWindow.rootViewController && [KWindow.rootViewController isKindOfClass:UITabBarController.class]) {
                UITabBarController *tabbarCon = (UITabBarController *)KWindow.rootViewController;
                tabbarCon.selectedIndex = 0;
            }
            
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    } fail:^(NSError *err) {
        [LICGToast showWithText:@"登录失败!"];
    }];
}

- (IBAction)closeClick:(id)sender {
    UITabBarController *tabCon = (UITabBarController *)KWindow.rootViewController;
    tabCon.selectedIndex = 0;
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
